package pattern.singleton;

import java.lang.reflect.Constructor;

// 枚举单例
public enum  EnumSingle {
    
    INSTANCE;
    static {
        System.out.println("create");
    }
    public EnumSingle getInstance(){
        System.out.println("create");
        
        return INSTANCE;
    }
    
}

class Test{
    public static void main(String[] args) throws Exception{
        EnumSingle instance = EnumSingle.INSTANCE;
//        EnumSingle instance1 = instance.getInstance();
        
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class, int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle instance1 = declaredConstructor.newInstance();
//
        System.out.println(instance.getDeclaringClass());
        System.out.println(instance1.getDeclaringClass());
    }
}
